logger: always update header when read from stdin
authorKarel Zak <kzak@redhat.com>
Tue, 1 Nov 2022 09:30:06 +0000 (10:30 +0100)
committerChris Hofstaedtler <zeha@debian.org>
Mon, 13 Feb 2023 08:48:21 +0000 (08:48 +0000)
commite844a4cf3a771f261ac9fa36ebd613ee179a6b23
treee1573a6d1145ad1c4bb2868753358d2207092154
parente2f609ab195ba4e3bacd4328bd1f25c42cec1d06
logger: always update header when read from stdin

The current code updates the header only when the priority has been
changed. It's incorrect because wanted is a valid header or each entry
(don't forget that logger for stdin use-case is used in pipe to log
long-time running processes).

This patch also fixes the initial timestamp; it was originally generated
on logger startup, it now generates the header on the first message.

$ (sleep 2; date; sleep 2; date; sleep 2; date) | logger --stderr --no-act

old:
<13>Nov  1 10:42:14 kzak: Tue Nov  1 10:42:16 AM CET 2022
<13>Nov  1 10:42:14 kzak: Tue Nov  1 10:42:18 AM CET 2022
<13>Nov  1 10:42:14 kzak: Tue Nov  1 10:42:20 AM CET 2022

new:
<13>Nov  1 10:19:02 kzak: Tue Nov  1 10:19:02 AM CET 2022
<13>Nov  1 10:19:04 kzak: Tue Nov  1 10:19:04 AM CET 2022
<13>Nov  1 10:19:06 kzak: Tue Nov  1 10:19:06 AM CET 2022

Fixes: https://github.com/util-linux/util-linux/issues/1866
Signed-off-by: Karel Zak <kzak@redhat.com>
Gbp-Pq: Topic upstream
Gbp-Pq: Name logger-always-update-header-when-read-from-stdin.patch
misc-utils/logger.c